---@param record {company_name: string, company_address: string, company_telephone: string, company_mail: string, invoice_number: string, period: string, client_name: string, client_code: string, address: string, city: string, meter_code: string, solar_fee: string, day_fee: string, night_fee: string, meter_rent: string, vat: string, solar_kwh: string, day_kwh: string, night_kwh: string}
---@return {company_name: string, company_address: string, company_telephone: string, company_mail: string, invoice_number: string, period: string, client_name: string, client_code: string, address: string, city: string, meter_code: string, solar_fee: string, day_fee: string, night_fee: string, meter_rent: string, vat: string, solar_kwh: string, day_kwh: string, night_kwh: string, solar_chf: string, day_chf: string, night_chf: string, total_without_vat: string, vat_amount: string, total: string}
local parse_record = function (record)
    local solar_chf = ('%.2f'):format(tonumber(record.solar_fee) * tonumber(record.solar_kwh) / 100)
    local day_chf = ('%.2f'):format(tonumber(record.day_fee) * tonumber(record.day_kwh) / 100)
    local night_chf = ('%.2f'):format(tonumber(record.night_fee) * tonumber(record.night_kwh) / 100)
    local total_without_vat = ('%.2f'):format(tonumber(solar_chf) + tonumber(day_chf) + tonumber(night_chf) + tonumber(record.meter_rent))
    local vat_amount = ('%.2f'):format(tonumber(record.vat) / 100 * total_without_vat)
    local total = ('%.2f'):format(total_without_vat + vat_amount)
    return {
        company_name = record.company_name,
        company_address = record.company_address,
        company_telephone = record.company_telephone,
        company_mail = record.company_mail,
        invoice_number = record.invoice_number,
        period = record.period,
        client_name = record.client_name,
        client_code = record.client_code,
        address = record.address,
        city = record.city,
        meter_code = record.meter_code,
        solar_fee = record.solar_fee,
        day_fee = record.day_fee,
        night_fee = record.night_fee,
        meter_rent = record.meter_rent,
        vat = record.vat,
        solar_kwh = record.solar_kwh,
        day_kwh = record.day_kwh,
        night_kwh = record.night_kwh,
        solar_chf = solar_chf,
        day_chf = day_chf,
        night_chf = night_chf,
        total_without_vat = total_without_vat,
        vat_amount = vat_amount,
        total = total
    }
end

local parse_data = function (data)
    local newData = {}
    for index, record in ipairs(data) do
        newData[index] = parse_record(record)
    end
    return newData
end

return parse_data
